/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../../tools/PacketReader.h"
#include "../../tools/PacketCreator.h"
#include "../world/Parties.h"
#include "PlayerHandler.h"
#include "../../server/Player.h"
#include "../world/World.h"

void PlayerHandler::partyOperationHandle(PacketReader& packet) {
	Parties* parties = player->getWorld()->getParties();
	char op = packet.read();
	switch (op) {
		case 0x01:
			parties->create(player);
			break;
		case 0x02:
			parties->leave(player);
			break;
		case 0x03:
			parties->join(player, packet.readInt());
			break;
		case 0x04:
			parties->invite(player, packet.readString());
			break;
		case 0x05:
			parties->expel(player, packet.readInt());
			break;
		case 0x06:
			parties->changeLeader(player, packet.readInt());
			break; 
	}
}

void PlayerHandler::deniedPartyInviteHandle(PacketReader& packet) {
	char op = packet.read();
	Player* from = player->getWorld()->getPlayerByName(packet.readString());
	if (from != 0) {
		if (op == 0x15) {
			from->send(PacketCreator().partyError(21, player->getName()));
		} else {
			from->send(PacketCreator().partyError(23, player->getName()));
		}
	}
	player->setPartyInvite(0);
}